import React from 'react';
import {
  View,
  Text,
} from 'react-native';

import CommonChatItemView from '../common/CommonChatItemView';
import SizeUtils from '../../common/SizeUtils';
import UserRequestOtherDataAction from '../../actions/user/UserRequestOtherDataAction';

export default class QZ_ChatItemView extends CommonChatItemView {
    constructor(props) {
      super(props);

      this.state.userData = {avatar_url:""}
    }

    componentDidMount() {
      super.componentDidMount();
      this._requestOtherUserData();
    }

    shouldComponentUpdate(nextProps, nextState) {
      return nextState.visible != this.state.visible ||
        nextState.delayFinish != this.state.delayFinish ||
        nextState.userData.avatar_url != this.state.userData.avatar_url ||
        nextProps.data.id != this.props.data.id;
    }

    componentWillUpdate(nextProps, nextState) {
      if(nextState.isResponeUpdate === true) {
        nextState.isResponeUpdate = false;
      }
    }

    _checkIsSelf() {
      return this.props.data.isSelf;
    }

    _getSelfAvarta() {
      return this.props.selfData.avatar_url;
    }

    _getUserData() {
      return this.state.userData;
    }

    _renderContent() {
      return (
        <Text style={{
            color: this._checkIsSelf() ? "#ffffff" : "#666666",
            fontSize: SizeUtils.translateFontSizeToCode(24),
            lineHeight:SizeUtils.translateFontSizeToCode(34),
          }}>{this._getContent()}
        </Text>
      )
    }

    _getContent() {
      if(this._checkIsSelf() === true) {
        return this.props.data.msg ? this.props.data.msg.replace(/\n$/g, '') : ""
      }
      else {
        return this.props.data.data ? this.props.data.data.replace(/\n$/g, '') : "";
      }
    }

    _renderTime() {
      return (
        <View style={{paddingTop:SizeUtils.translateDesignHeightToCode(40),
            paddingLeft:SizeUtils.translateDesignWidthToCode(20),
            paddingRight:SizeUtils.translateDesignWidthToCode(20),}}>
          <Text style={{color:"#999999", fontSize:SizeUtils.translateFontSizeToCode(24)}}>

          </Text>
        </View>
      )
    }

    _requestOtherUserData() {
      if(this.props.data.from != undefined) {
        new UserRequestOtherDataAction().call(this, {id:this.props.data.from, forceRequest:true})
      }
    }
}
